package com.food.dao.service;

import java.io.InputStream;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import com.food.dao.MbproductDAOJdbc;
import com.food.dao.ProductDAOJdbc;
import com.food.dao.in.MbproductDAO;
import com.food.dao.in.ProductDAO;
import com.food.model.Mbproduct;
import com.food.model.Member;
import com.food.model.Product;

public class ProductService {

	ProductDAO dao = new ProductDAOJdbc();
	
	public void insertProduct(Product bean){
		dao.insertProduct(bean);
	}
	
	public void deleteProduct(Product bean){
		dao.deleteProduct(bean.getPid());
	}
	

	public List<Product> findAllProduct() {
		return dao.findAllProduct();

	}
	
	public List<Product> findAllProductPages(int pagesize,int pageindex){
		return dao.findAllProductPages(pagesize,pageindex);
	}

	
	public List<Product> find_Search_Pages(int pagesize, int pageindex,String search){
		
		return dao.find_Search_Pages(pagesize,pageindex,search);
	}
	
	
	public Product findOneProduct(int pid) {
		return dao.findOneProduct(pid);

	}

	public List<Product> findProductByCountry(String pcountry) {

		return dao.findProductByCountry(pcountry);
	}

	public List<Product> findProductByCooker(String pcooker) {

		return dao.findProductByCooker(pcooker);
	}
	
	public List<Product> findProductByName(String pname){
		
		return dao.findProductByName(pname);
	}
	
	public Set<String> getCountry() {

		List<Product> fAll = dao.findAllProduct();
		// country
		Set<String> fCountry = new LinkedHashSet<String>();

		for (Product gCountry : fAll) {
			fCountry.add(gCountry.getPcountry());
		}

		return fCountry;
	}

	public Set<String> getCooker() {

		List<Product> fAll = dao.findAllProduct();
		//cooker
		Set<String> fCooker = new LinkedHashSet<String>();

		for (Product gCooker : fAll) {
			fCooker.add(gCooker.getPcooker());

		}

		return fCooker;

	}

	public static void main(String[] args) {
		/* 叫用服務 */
		ProductService prodsv = new ProductService();
		// System.out.println(prodsv.findOneProduct(1));

		Set<String> xx = prodsv.getCountry();

		for (String zz : xx) {
			System.out.println(zz);
		}

	}
}
